package com.bristua.common.utils;


import com.bristua.common.bean.Result;
import com.bristua.common.enums.CommonCode;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2019/3/24.
 */
public class HandleResultUtil {

    public static Result commonResult(int code, String msg){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static Result addSuccessResult(){
        Result result = new Result();
        result.setCode(CommonCode.INSERT_SUCCESS.getCode());
        result.setMsg(CommonCode.INSERT_SUCCESS.getMsg());
        return result;
    }

    public static Result updateSuccessResult(){
        Result result = new Result();
        result.setCode(CommonCode.UPDATE_SUCCESS.getCode());
        result.setMsg(CommonCode.UPDATE_SUCCESS.getMsg());
        return result;
    }

    public static Result delSuccessResult(){
        Result result = new Result();
        result.setCode(CommonCode.DELETE_SUCCESS.getCode());
        result.setMsg(CommonCode.DELETE_SUCCESS.getMsg());
        return result;
    }


    public static Result querySuccessResult(Object data){
        Result result = new Result();
        result.setCode(CommonCode.QUERY_SUCCESS.getCode());
        result.setMsg(CommonCode.QUERY_SUCCESS.getMsg());
        if(data!=null && data instanceof List){
            Map map = new HashMap<>();
            map.put("list",data);
            result.setData(map);
        }else{
            result.setData(data);
        }
        return result;
    }
}
